package com.woniuxy.utils;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

//订单状态枚举类
public enum OrderStateEnum {

    //1. 定义枚举值
    OPT_CANCEL("0","取消","CANCEL"),
    OPT_CREATE("10","未支付","CREATE"),
    OPT_ONLINE_PAY("20","待发货","ONLINE_PAY"),
    OPT_BUSI_AUDIT("14","业务审核","BUSI_PAY"),
    OPT_FINA_AUDIT("17","财务审核","FINA_AUDIT"),
    OPT_CON_MENT("25","发货中","CON_MENT"),
    OPT_DISM_TING("100","已拆单","DISM_TING"),
    OPT_DISPATCH("30","已发货","DISPATCH"),
    OPT_FINISH("50","已完成","FINISH"),
    OPT_UNKNOWN("-1","未知","UNKNOWN");

    //2. 定义成员变量
    /**
     * 订单状态编码
     */
    private String code;
    /**
     * 订单状态名称
     */
    private String stateName;
    /**
     * 订单状态英文名称
     */
    private String stateEnName;

	//3. 私有的构造函数


	/**
     * @param code
     * @param stateName
     * @param stateEnName
     */
    OrderStateEnum(String code, String stateName, String stateEnName) {
        this.code = code;
        this.stateName = stateName;
        this.stateEnName = stateEnName;
    }

    //get/set方法
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getStateName() {
        return stateName;
    }
    public String getStateEnName() {
        return stateEnName;
    }
    
    //4. 定义自己的方法
    /**
     * 根据编码获取对应的状态名称
     * @param code
     * @return
     */
    public static String getNameByCode(String code){
        //5. values()获取所有的枚举值
    	OrderStateEnum[] orderStates =  OrderStateEnum.values();
        for(int i=0;i<orderStates.length;i++){
        	OrderStateEnum orderState = orderStates[i];
            if(orderState.getCode().equals(code)){
                return orderState.getStateName();
            }
        }
        return code;
    }
    
    /**
     * 获取所有的订单状态编码及对应的状态名称
     * @return
     */
    public static List<Map<String,String>> getAllOrderState(){
        List<Map<String,String>> allPayment = new LinkedList<>();
        OrderStateEnum[] values = OrderStateEnum.values();
        if(values.length>0){
            for(int i=0;i<values.length;i++){
            	OrderStateEnum orderState = values[i];
                Map<String,String> map = new HashMap<>();
                map.put(orderState.getCode(),orderState.stateName);
                allPayment.add(map);
            }
        }
        return allPayment;
    }
}
